package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.InvoiceDao;
import cn.itcast.dao.cargo.ShippingOrderDao;
import cn.itcast.domain.cargo.Invoice;
import cn.itcast.domain.cargo.InvoiceExample;
import cn.itcast.domain.cargo.ShippingOrder;
import cn.itcast.service.cargo.InvoiceService;
import cn.itcast.vo.ContractProductVo;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import java.util.UUID;

//合同
@Service
public class InvoiceServiceImpl implements InvoiceService{

    @Autowired
    private InvoiceDao invoiceDao;

    @Autowired
    private ShippingOrderDao shippingOrderDao;

    @Override
    public Invoice findById(String id) {
        return invoiceDao.selectByPrimaryKey(id);
    }

    @Override
    public void save(Invoice invoice) {
        ShippingOrder shippingOrder = shippingOrderDao.selectByPrimaryKey(invoice.getInvoiceId());
        shippingOrder.setState(2);
        shippingOrderDao.updateByPrimaryKeySelective(shippingOrder);
        invoice.setState(0);
        invoice.setCreateTime(new Date());
        invoiceDao.insertSelective(invoice);
    }

    @Override
    public void update(Invoice invoice) {
        invoiceDao.updateByPrimaryKeySelective(invoice);
    }

    @Override
    public void delete(String id) {
        invoiceDao.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo findAll(InvoiceExample example, int page, int size) {
        PageHelper.startPage(page,size);
        List<Invoice> list = invoiceDao.selectByExample(example);
        return new PageInfo(list);
    }

}
